home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Sound / Amster / Source / gui.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-19  |  24.8 KB  |  756 lines

  1. /*
  2. ** Amster - Main GUI
  3. ** Copyright © 1999-2001 by Gürer Özen
  4. ** Copyright © 2000-2001 by Jacob Laursen
  5. **
  6. ** This program is free software; you can redistribute it and/or modify
  7. ** it under the terms of the GNU General Public License as published by
  8. ** the Free Software Foundation; either version 2 of the License, or
  9. ** (at your option) any later version.
  10. **
  11. ** This program is distributed in the hope that it will be useful,
  12. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ** GNU General Public License for more details.
  15. **
  16. ** You should have received a copy of the GNU General Public License
  17. ** along with this program; if not, write to the Free Software
  18. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19. */
  20.  
  21. #include "amster.h"
  22.  
  23. #include <exec/memory.h>
  24.  
  25. #include <proto/asl.h>
  26. #include <proto/dos.h>
  27. #include <proto/icon.h>
  28. #include <proto/locale.h>
  29. #include <proto/utility.h>
  30.  
  31. #include <libraries/gadtools.h>
  32. #include <libraries/asl.h>
  33.  
  34. #include <MUI/Lamp_mcc.h>
  35. #include <MUI/NListview_mcc.h>
  36. #include <MUI/textinput_mcc.h>
  37.  
  38. #include "chatline.h"
  39. #include "url.h"
  40. #include "amster_Cat.h"
  41.  
  42. struct Library *MUIMasterBase = NULL;
  43. struct LocaleBase *LocaleBase = NULL;
  44.  
  45. int UseLamps = 0;
  46. int UseTWF = 0;
  47. struct guidata mygui;
  48. struct guidata *gui = &mygui;
  49. enum OnlineState gui_onlinestate = OFFLINE;
  50. listener l;
  51.  
  52. void gui_free(void);
  53. int gui_setup(void);
  54. MUI_HOOK_DECL(gui_handle, Object *app, u_long *id);
  55. void gui_about(void);
  56. void gui_appicon(int t);
  57.  
  58. struct Hook handleHook = {{0, 0}, &gui_handle, NULL, NULL};
  59.  
  60. static muiclass amster_mccs[] =
  61. {
  62.     { MUIC_Text, sizeof(struct urldata), &url_dispatch, &mygui.url_mcc },
  63.     { MUIC_String, sizeof(struct chatlinedata), &chatline_dispatch, &mygui.chatline_mcc },
  64.     { MUIC_Group, sizeof(struct paneldata), &panel_dispatch, &mygui.panel_mcc },
  65.     { MUIC_Group, sizeof(struct searchdata), &search_dispatch, &mygui.search_mcc },
  66.     { MUIC_Group, sizeof(struct resultdata), &resultview_dispatch, &mygui.resultview_mcc },
  67.     { MUIC_Window, sizeof(struct TransferData), &dl_dispatch, &mygui.dl_mcc },
  68.     { MUIC_Window, sizeof(struct TransferData), &ul_dispatch, &mygui.ul_mcc },
  69.     { MUIC_Window, sizeof(struct shdata), &share_dispatch, &mygui.share_mcc },
  70.     { MUIC_Window, sizeof(struct prfdata), &prf_dispatch, &mygui.prf_mcc },
  71.     { MUIC_Window, sizeof(struct infodata), &info_dispatch, &mygui.info_mcc },
  72.     { MUIC_Window, 0, &about_dispatch, &mygui.about_mcc },
  73.     { MUIC_Window, sizeof(struct msgdata), &msg_dispatch, &mygui.msg_mcc },
  74.     { MUIC_Window, sizeof(struct chatdata), &chat_dispatch, &mygui.chat_mcc },
  75.     { MUIC_Window, sizeof(struct NavigatorData), &NavigatorDispatch, &mygui.navi_mcc },
  76.     { MUIC_Window, sizeof(struct HotlistData), &HotlistDispatch, &mygui.hotlist_mcc },
  77.     { MUIC_Window, sizeof(struct ChannelListData), &ChannelListDispatch, &mygui.channellist_mcc },
  78.  
  79.     { NULL, 0, NULL, NULL }
  80. };
  81.  
  82.  
  83. void gui_run(unsigned long tcpsig)
  84. {
  85.     ULONG sigs=0;
  86.  
  87.     memset(gui, 0, sizeof(struct guidata));
  88.     if (gui_setup()) {
  89.         prf_event(PRFE_STARTUP);
  90.         DoMethod(gui->shwin, SHARE_LOAD);
  91.         while (1) {
  92.             while (DoMethod(gui->app, MUIM_Application_NewInput, &sigs) != MUIV_Application_ReturnID_Quit) {
  93.                 if (sigs) {
  94.                     sigs = Wait(sigs | SIGBREAKF_CTRL_C | tcpsig | th_sigmask);
  95.                     if (sigs & SIGBREAKF_CTRL_C) break;
  96.                     if (sigs & tcpsig) nap_listen();
  97.                     if (sigs & th_sigmask) th_poll();
  98.                 }
  99.             }
  100.             if (!dl_count && !ul_count) break;
  101.             if ((dl_count || ul_count) && MUI_Request(gui->app, gui->win, 0L,
  102.                                        (char *)MSG_REALLYQUIT_TITLE,
  103.                                        (char *)MSG_REALLYQUIT_GAD,
  104.                                        (char *)MSG_REALLYQUIT)) break;
  105.         }
  106.         prf_event(PRFE_EXIT);
  107.         if (prf->autosave && sharechanged) DoMethod(gui->shwin, SHARE_SAVE);
  108.         if (prf->ServerList > 0 && ServerListChanged) DoMethod(gui->WI_Navigator, NAVI_SAVE);
  109.         if (HotlistChanged) DoMethod(gui->WI_Hotlist, HOTLIST_SAVE);
  110.         if (gui_onlinestate > OFFLINE) nap_logout();
  111. #ifdef AMSTER_DEBUG
  112.         if (l && l->t) Signal(l->t->task, SIGBREAKF_CTRL_F);
  113. #endif
  114.     }
  115.     th_exit();
  116.     gui_free();
  117. }
  118.  
  119.  
  120. void gui_free(void)
  121. {
  122.     gui_appicon(-1);
  123.     if (gui->app) MUI_DisposeObject(gui->app);
  124.     lamp_dispose();
  125.     if (QueueClass) MUI_DeleteCustomClass(QueueClass);
  126.     if (ResultviewContext) MUI_DeleteCustomClass(ResultviewContext);
  127.     if (UserlistContext) MUI_DeleteCustomClass(UserlistContext);
  128.     mui_classes_cleanup(amster_mccs);
  129.     if (locale) CloseLocale(locale);
  130.     if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
  131.     if (MUIMasterBase) CloseLibrary(MUIMasterBase);
  132. }
  133.  
  134.  
  135. int gui_setup(void)
  136. {
  137.     long winopen;
  138.     u_long *MI_Navigator, *MI_Connect, *MI_ConnectTo, *MI_Reconnect, *MI_Disconnect;
  139.     u_long *aboutmenu, *muimenu, *helpmenu, *hidemenu, *quitmenu;
  140.     u_long *MI_Open, *MI_Merge, *MI_Save, *MI_SaveAs;
  141.     u_long *debugmenu, *dlmenu, *ulmenu, *sharemenu, *usermenu, *chatmenu, *MI_Hotlist;
  142.     u_long *muiprfmenu, *prfmenu, *MI_LastSaved, *saveprfmenu;
  143.     u_long *rxexemenu;
  144.  
  145.     struct Library *NListBase;
  146.     struct Library *LampBase;
  147.     struct Library *TWFBase;
  148.     struct Library *TextinputBase;
  149.  
  150.     localize_array(nap_linktype);
  151.  
  152.     MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN);
  153.     if (!MUIMasterBase) {
  154.         printf(MSG_NO_LIBRARY, MUIMASTER_NAME, MUIMASTER_VMIN);
  155.         return(0);
  156.     }
  157.  
  158.     LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library", 37L);
  159.     if (!LocaleBase) {
  160.         printf(MSG_NO_LIBRARY, "locale.library", 37);
  161.         return(0);
  162.     }
  163.     locale = OpenLocale(NULL);
  164.  
  165.     NListBase = OpenLibrary("LIBS:MUI/NList.mcc", 19);
  166.     if (!NListBase) {
  167.         printf(MSG_NO_LIBRARY, "NList.mcc", 19);
  168.         return(0);
  169.     }
  170.     if (NListBase->lib_Version == 19 && NListBase->lib_Revision < 97) {
  171.         printf(MSG_NO_LIBRARY, "NList.mcc", 19);
  172.         CloseLibrary(NListBase);
  173.         return(0);
  174.     }
  175.     CloseLibrary(NListBase);
  176.  
  177.     TextinputBase = OpenLibrary("LIBS:MUI/Textinput.mcc", 26);
  178.     if (!TextinputBase) {
  179.         printf(MSG_NO_LIBRARY, "Textinput.mcc", 26);
  180.         return(0);
  181.     }
  182.     CloseLibrary(TextinputBase);
  183.  
  184.     LampBase = OpenLibrary("LIBS:MUI/Lamp.mcc", 11);
  185.     if (LampBase) {
  186.         if (!(LampBase->lib_Version == 11 && LampBase->lib_Revision == 0))
  187.             UseLamps = 1;
  188.         CloseLibrary(LampBase);
  189.     }
  190.     TWFBase = OpenLibrary("LIBS:MUI/TWFmultiLED.mcc", 12);
  191.     if (TWFBase) {
  192.         if (!(TWFBase->lib_Version == 12 && TWFBase->lib_Revision < 6))
  193.             UseTWF = 1;
  194.         CloseLibrary(TWFBase);
  195.     }
  196.  
  197.     if (!prf_load("ENV:"AMSTER_PREFS)) prf_load("ENVARC:"AMSTER_PREFS);
  198.  
  199. #ifdef AMSTER_DEBUG
  200.     if (prf->port) {
  201.         l = malloc(sizeof(_listener));
  202.         if (l) {
  203.             memset(l, 0, sizeof(_listener));
  204.             l->t = th_spawn(ListenerMsgHandler, "Amster listener", &createlistener, 0, l);
  205.         }
  206.     }
  207. #endif
  208.  
  209.     lamp_create();
  210.  
  211.     if (!(ResultviewContext = MUI_CreateCustomClass(NULL, MUIC_NList, NULL, sizeof(struct ResultviewContextData), &ResultviewContextDispatcher))) return 0;
  212.     if (!(UserlistContext = MUI_CreateCustomClass(NULL, MUIC_NList, NULL, sizeof(struct UserlistContextData), &UserlistContextDispatcher))) return 0;
  213.  
  214.     if(!mui_classes_setup(amster_mccs)) return(0);
  215.  
  216.     gui->iconpanel = NewObject(gui->panel_mcc->mcc_Class, NULL, TAG_DONE);
  217.     gui->rect = NULL;
  218.  
  219.     gui->app = ApplicationObject,
  220.         MUIA_Application_Title,       "Amster",
  221. #ifdef AMSTER_DEBUG
  222.         MUIA_Application_Version,     "$VER: Amster "AMSTER_VERSION" ("AMSTER_DATE") Build #"AMSTER_BUILD,
  223. #else
  224.         MUIA_Application_Version,     "$VER: Amster "AMSTER_VERSION" ("AMSTER_DATE")",
  225. #endif
  226.         MUIA_Application_Author,      "Jacob Laursen",
  227.         MUIA_Application_Description, MSG_CX_DESCRIPTION,
  228.         MUIA_Application_Base,        "AMSTER",
  229.         MUIA_Application_Commands,    &rexx_cmds,
  230.         MUIA_Application_HelpFile,    AMSTER_HELP,
  231.         MUIA_Application_Menustrip,   MenustripObject,
  232.             Child, MenuObject,
  233.                 MUIA_Menu_Title, MSG_AMSTER_MENU,
  234.                 Child, MI_Navigator = makemenu(MSG_AMSTER_NAVIGATOR),
  235.                 Child, makemenu(NULL),
  236.                 Child, MI_Connect = makemenu(MSG_AMSTER_CONNECT),
  237.                 Child, MI_ConnectTo = makemenu(MSG_AMSTER_CONNECTTO),
  238.                 Child, MI_Reconnect = makemenu(MSG_AMSTER_RECONNECT),
  239.                 Child, MI_Disconnect = makemenu(MSG_AMSTER_DISCONNECT),
  240.                 Child, makemenu(NULL),
  241.                 Child, aboutmenu = makemenu(MSG_AMSTER_ABOUT),
  242.                 Child, muimenu = makemenu(MSG_AMSTER_ABOUTMUI),
  243.                 Child, helpmenu = makemenu(MSG_AMSTER_HELP),
  244.                 Child, makemenu(NULL),
  245.                 Child, hidemenu = makemenu(MSG_AMSTER_HIDE),
  246.                 Child, quitmenu = makemenu(MSG_AMSTER_QUIT),
  247.             End,
  248.             Child, MenuObject,
  249.                 MUIA_Menu_Title, MSG_PROJECT_MENU,
  250.                 Child, MI_Open   = makemenu(MSG_PROJECT_OPEN),
  251.                 Child, MI_Merge  = makemenu(MSG_PROJECT_MERGE),
  252.                 Child, MI_Save   = makemenu(MSG_PROJECT_SAVE),
  253.                 Child, MI_SaveAs = makemenu(MSG_PROJECT_SAVEAS),
  254.             End,
  255.             Child, MenuObject,
  256.                 MUIA_Menu_Title, MSG_WINDOWS_MENU,
  257.                 Child, debugmenu = makemenu(MSG_WINDOWS_DEBUG),
  258.                 Child, sharemenu = makemenu(MSG_WINDOWS_SHARE),
  259.                 Child, dlmenu = makemenu(MSG_WINDOWS_DOWNLOAD),
  260.                 Child, ulmenu = makemenu(MSG_WINDOWS_UPLOAD),
  261.                 Child, usermenu = makemenu(MSG_WINDOWS_USER),
  262.                 Child, chatmenu = makemenu(MSG_WINDOWS_CHAT),
  263.                 Child, MI_Hotlist = makemenu(MSG_WINDOWS_HOTLIST),
  264.             End,
  265.             Child, MenuObject,
  266.                 MUIA_Menu_Title, MSG_SETTINGS_MENU,
  267.                 Child, gui->iconpanelmenu = maketmenu(MSG_SETTINGS_ICONPANEL),
  268.                 Child, makemenu(NULL),
  269.                 Child, muiprfmenu = makemenu(MSG_SETTINGS_MUI),
  270.                 Child, prfmenu = makemenu(MSG_SETTINGS_CONFIG),
  271.                 Child, makemenu(NULL),
  272.                 Child, MI_LastSaved = makemenu(MSG_SETTINGS_LASTSAVED),
  273.                 Child, saveprfmenu = makemenu(MSG_SETTINGS_SAVE),
  274.             End,
  275.             Child, MenuObject,
  276.                 MUIA_Menu_Title, MSG_AREXX_MENU,
  277.                 Child, rxexemenu = makemenu(MSG_AREXX_EXECUTE),
  278.             End,
  279.         End,
  280.  
  281.         SubWindow, gui->win = WindowObject,
  282.         MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  283.         MUIA_Window_Title, "Amster v"AMSTER_VERSION,
  284.         WindowContents, gui->maingrp = HGroup,
  285.             Child, VGroup,
  286.                 Child, gui->searchpanel = NewObject(gui->search_mcc->mcc_Class, NULL, TAG_DONE),
  287.                 Child, RectangleObject,
  288.                     MUIA_FixHeight, 8,
  289.                     MUIA_Rectangle_HBar, TRUE,
  290.                 End,
  291.                 Child, gui->statgrp = HGroup,
  292.                     Child, gui->stat = TextObject,
  293.                         TextFrame,
  294.                         MUIA_Background, MUII_TextBack,
  295.                         MUIA_Text_PreParse, "\33c",
  296.                     End,
  297.                 End,
  298.                 Child, HGroup,
  299.                     Child, gui->inbut  = SimpleButton(MSG_CONNECT_GAD),
  300.                     Child, gui->outbut = SimpleButton(MSG_DISCONNECT_GAD),
  301.                     Child, gui->rebut  = SimpleButton(MSG_RECONNECT_GAD),
  302.                 End,
  303.             End,
  304. /*
  305.             Child, gui->rect = HGroup,
  306.                 Child, RectangleObject,
  307.                     MUIA_FixWidth, 4,
  308.                     MUIA_Rectangle_VBar, TRUE,
  309.                 End,
  310.                 Child, gui->iconpanel = NewObject(gui->panel_mcc->mcc_Class, NULL, TAG_DONE),
  311.             End,
  312. */
  313.         End,
  314.         End,
  315.  
  316.         SubWindow, gui->WI_ConnectTo = WindowObject,
  317.         MUIA_HelpNode, "connectto",
  318.         MUIA_Window_Title, MSG_CONNECTTO_TITLE,
  319.         MUIA_Window_ID, MAKE_ID('C','O','N','N'),
  320.         WindowContents, VGroup,
  321.             Child, HGroup,
  322.                 Child, ColGroup(2),
  323.                     Child, Label2(MSG_CONNECTTO_SERVER),
  324.                     Child, HGroup,
  325.                         Child, gui->ST_ConnectServer = TextinputObject,
  326.                             StringFrame,
  327.                             MUIA_Textinput_Multiline, FALSE,
  328.                             MUIA_String_AdvanceOnCR, TRUE,
  329.                             MUIA_String_Accept, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-",
  330.                             MUIA_CycleChain, 1,
  331.                         End,
  332.                         Child, Label2(MSG_CONNECTTO_PORT),
  333.                         Child, gui->ST_ConnectPort = TextinputObject,
  334.                             StringFrame,
  335.                             MUIA_Textinput_Multiline, FALSE,
  336.                             MUIA_String_AdvanceOnCR, TRUE,
  337.                             MUIA_HorizWeight, 45,
  338.                             MUIA_String_Accept, "0123456789",
  339.                             MUIA_String_MaxLen, 6,
  340.                             MUIA_CycleChain, 1,
  341.                         End,
  342.                     End,
  343.                     Child, Label2(MSG_CONNECTTO_USERNAME),
  344.                     Child, gui->ST_ConnectUser = TextinputObject,
  345.                         StringFrame,
  346.                         MUIA_Textinput_Multiline, FALSE,
  347.                         MUIA_String_Reject, ":%$ ",
  348.                         MUIA_String_AdvanceOnCR, TRUE,
  349.                         MUIA_CycleChain, 1,
  350.                     End,
  351.                     Child, Label2(MSG_CONNECTTO_PASSWORD),
  352.                     Child, gui->ST_ConnectPw = StringObject,
  353.                         StringFrame,
  354.                         MUIA_String_Reject, " ",
  355.                         MUIA_String_AdvanceOnCR, TRUE,
  356.                         MUIA_String_Secret, TRUE,
  357.                         MUIA_CycleChain, 1,
  358.                     End,
  359.                 End,
  360.             End,
  361.             Child, maketoggle(MSG_CONNECTTO_REG, &gui->TG_ConnectReg),
  362.             Child, gui->BT_ConnectServer = SimpleButton(MSG_CONNECTTO_CONNECT_GAD),
  363.         End,
  364.         End,
  365.  
  366.         SubWindow, gui->awin = NewObject(gui->about_mcc->mcc_Class, NULL, TAG_DONE),
  367.         SubWindow, gui->swin = NewObject(gui->prf_mcc->mcc_Class, NULL, TAG_DONE),
  368.         SubWindow, gui->iwin = NewObject(gui->info_mcc->mcc_Class, NULL, TAG_DONE),
  369.         SubWindow, gui->dwin = NewObject(gui->dl_mcc->mcc_Class, NULL, TAG_DONE),
  370.         SubWindow, gui->uwin = NewObject(gui->ul_mcc->mcc_Class, NULL, TAG_DONE),
  371.         SubWindow, gui->shwin = NewObject(gui->share_mcc->mcc_Class, NULL, TAG_DONE),
  372.         SubWindow, gui->mwin = NewObject(gui->msg_mcc->mcc_Class, NULL, TAG_DONE),
  373.         SubWindow, gui->WI_Navigator = NewObject(gui->navi_mcc->mcc_Class, NULL, TAG_DONE),
  374.         SubWindow, gui->WI_Hotlist = NewObject(gui->hotlist_mcc->mcc_Class, NULL, TAG_DONE),
  375.         SubWindow, gui->WI_ChannelList = NewObject(gui->channellist_mcc->mcc_Class, NULL, TAG_DONE),
  376.  
  377.     End;
  378.  
  379.     if (!gui->app) {
  380.         printf(MSG_APP_ERROR);
  381.         return(0);
  382.     }
  383.  
  384.     DoMethod(gui->inbut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, CONNECT);
  385.     DoMethod(gui->outbut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, DISCONNECT);
  386.     DoMethod(gui->rebut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, RECONNECT);
  387.  
  388.     DoMethod(gui->iconpanelmenu, MUIM_Notify, MUIA_Menuitem_Checked, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, UPDATEPANEL);
  389.  
  390.     DoMethod(MI_Navigator, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->WI_Navigator, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  391.     DoMethod(MI_Connect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, CONNECT);
  392.     DoMethod(MI_ConnectTo, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->WI_ConnectTo, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  393.     DoMethod(MI_Reconnect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, RECONNECT);
  394.     DoMethod(MI_Disconnect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, DISCONNECT);
  395.     DoMethod(gui->WI_ConnectTo, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, gui->WI_ConnectTo, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  396.  
  397.     /* Connect to... */
  398.  
  399.     DoMethod(gui->BT_ConnectServer, MUIM_Notify, MUIA_Pressed, FALSE, gui->app, 3, MUIM_CallHook, &handleHook, CONNECTSERVER);
  400.  
  401.     /* Pulldown menu */
  402.  
  403.     DoMethod(aboutmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->awin,3,MUIM_Set,MUIA_Window_Open,TRUE);
  404.     DoMethod(muimenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_AboutMUI,gui->win);
  405.     DoMethod(helpmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,5,MUIM_Application_ShowHelp,gui->win,AMSTER_HELP,0,0);
  406.     DoMethod(hidemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,3,MUIM_Set,MUIA_Application_Iconified,TRUE);
  407.     DoMethod(quitmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  408.  
  409.     DoMethod(MI_Open,   MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->shwin, 2, SHARE_LOADAS, 0);
  410.     DoMethod(MI_Merge,  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->shwin, 2, SHARE_LOADAS, 1);
  411.     DoMethod(MI_Save,   MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->shwin, 1, SHARE_SAVE);
  412.     DoMethod(MI_SaveAs, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->shwin, 1, SHARE_SAVEAS);
  413.  
  414.     DoMethod(debugmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENDEBUG);
  415.     DoMethod(dlmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENDL);
  416.     DoMethod(ulmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->uwin,1,UPLOAD_OPEN);
  417.     DoMethod(sharemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENSHARE);
  418.     DoMethod(usermenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENMSG);
  419.     DoMethod(chatmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_NEWCHAT);
  420.     DoMethod(MI_Hotlist, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->WI_Hotlist, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  421.  
  422.     DoMethod(muiprfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_OpenConfigWindow,0);
  423.     DoMethod(prfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENPRF);
  424.     DoMethod(MI_LastSaved, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->swin, 1, PRF_LASTSAVED);
  425.     DoMethod(saveprfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->swin,1,PRF_SAVEALL);
  426.  
  427.     DoMethod(rxexemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,3,MUIM_CallHook,&handleHook, EXECUTEAREXX);
  428.  
  429.     DoMethod(gui->win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,gui->app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  430.     DoMethod(gui->app, MUIM_Notify, MUIA_Application_Iconified, FALSE, gui->app,3, MUIM_CallHook, &handleHook, DEICONIFIED);
  431.  
  432.     if (UseLamps) DoMethod(gui->statgrp, OM_ADDMEMBER, gui->lamp = LampObject, MUIA_Lamp_Type, MUIV_Lamp_Type_Huge, MUIA_Lamp_Color, MUIV_Lamp_Color_Off, End);
  433.  
  434.     DoMethod(gui->searchpanel, SEARCH_SET);
  435.  
  436.     set(gui->ST_ConnectUser, MUIA_String_Contents, prf->user);
  437.     set(gui->ST_ConnectPw,   MUIA_String_Contents, prf->pass);
  438.     set(gui->TG_ConnectReg,  MUIA_Selected,        TRUE);
  439.  
  440.     if (prf->noiconpanel) {
  441.         set(gui->iconpanelmenu, MUIA_Menuitem_Checked, FALSE);
  442. /*        set(gui->rect, MUIA_ShowMe, FALSE);*/
  443.     }
  444.     else {
  445.         set(gui->iconpanelmenu, MUIA_Menuitem_Checked, TRUE);
  446.     }
  447.  
  448.     gui_appicon(0);
  449.     gui_state(OFFLINE);
  450.  
  451.     if (!UseLamps) gui_debug((char *)MSG_INFO_NOLAMPS);
  452.  
  453.     /* Set screen title for all windows */
  454.     DoMethod(gui->app, MUIM_MultiSet, MUIA_Window_ScreenTitle,
  455.         "Amster "AMSTER_VERSION" ("AMSTER_DATE") © 1999-2001 Gürer Özen & Jacob Laursen",
  456.         gui->win, gui->awin, gui->swin, gui->shwin, gui->mwin, gui->iwin,
  457.         gui->dwin, gui->uwin, gui->WI_ConnectTo, gui->WI_Navigator,
  458.         gui->WI_Hotlist, gui->WI_ChannelList, NULL);
  459.  
  460.     set(gui->win, MUIA_Window_Open, TRUE);
  461.     get(gui->win, MUIA_Window_Open, &winopen);
  462.     if (!winopen) {
  463.         printf(MSG_ERR_NOWINDOW);
  464.         return(0);
  465.     }
  466.  
  467.     if (!prf->user) DoMethod(gui->iconpanel, PANEL_OPENPRF);
  468.     /* If no account is configured, open configuration window */
  469.  
  470.     if (prf->user && prf->autocon) {
  471.         nap_login();
  472.         return(1);
  473.     }
  474.  
  475.     set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_NOTCONNECTED);
  476.     return(1);
  477. }
  478.  
  479.  
  480. MUI_HOOK(gui_handle, Object *app, u_long *id)
  481. {
  482.     u_long tmp;
  483.     char *buf;
  484.  
  485.     switch(*id) {
  486.         case CONNECT:
  487.             if (gui_onlinestate < CONNECTING) nap_login();
  488.             break;
  489.         case DISCONNECT:
  490.             nap_logout();
  491.             set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_NOTCONNECTED);
  492.             break;
  493.         case RECONNECT:
  494.             if (gui_onlinestate > OFFLINE) nap_logout();
  495.             nap_login();
  496.             break;
  497.         case CONNECTSERVER:
  498.             {
  499.             int port;
  500.  
  501.             if (gui_onlinestate > OFFLINE) nap_logout();
  502.             get(gui->ST_ConnectServer, MUIA_String_Contents, &buf);
  503.             get(gui->ST_ConnectPort,   MUIA_String_Integer,  &tmp);
  504.             port = (int)tmp;
  505.             get(gui->ST_ConnectUser,   MUIA_String_Contents, &gui->ConnectUser);
  506.             get(gui->ST_ConnectPw,     MUIA_String_Contents, &gui->ConnectPw);
  507.             get(gui->TG_ConnectReg,    MUIA_Selected,        &tmp);
  508.             set(gui->WI_ConnectTo, MUIA_Window_Open, FALSE);
  509.             if (tmp) prf->regflag = 2;
  510.             else prf->regflag = 0;
  511.  
  512.             nap_login_fromlist(buf, port);
  513.  
  514.             break;
  515.             }
  516.         case EXECUTEAREXX:
  517.             {
  518.             BPTR lock;
  519.             struct FileRequester *freq;
  520.             u_long win;
  521.             char DefaultDir[256] = "";
  522.  
  523.             lock = Lock("PROGDIR:Rexx/", ACCESS_READ);
  524.             if (lock) {
  525.                 NameFromLock(lock, DefaultDir, 255);
  526.                 UnLock(lock);
  527.             }
  528.  
  529.             get(gui->win, MUIA_Window_Window, &win);
  530.             freq = AllocAslRequestTags(ASL_FileRequest, TAG_DONE);
  531.             if (!freq) break;
  532.             tmp = AslRequestTags(freq,
  533.                 ASLFR_Window, win,
  534.                 ASLFR_TitleText, MSG_SELECTRX_TITLE,
  535.                 ASLFR_InitialDrawer, DefaultDir,
  536.                 ASLFR_DoSaveMode, FALSE,
  537.                 TAG_DONE);
  538.             if (tmp) {
  539.                 static char buf[512];
  540.                 strcpy(buf, freq->fr_Drawer);
  541.                 AddPart(buf, freq->fr_File,511);
  542.                 rexx_execute(buf, NULL);
  543.             }
  544.             FreeAslRequest(freq);
  545.             break;
  546.             }
  547.         case UPDATEPANEL:
  548.             GetAttr(MUIA_Menuitem_Checked, gui->iconpanelmenu, &tmp);
  549.             if (tmp==TRUE) {
  550.                 if (!gui->rect && DoMethod(gui->maingrp, MUIM_Group_InitChange)) {
  551.                     DoMethod(gui->maingrp, OM_ADDMEMBER,
  552.                         gui->rect = HGroup,
  553.                             Child, RectangleObject,
  554.                                 MUIA_FixWidth, 4,
  555.                                 MUIA_Rectangle_VBar, TRUE,
  556.                             End,
  557.                             Child, gui->iconpanel,
  558.                         End);
  559.                     DoMethod(gui->maingrp, MUIM_Group_ExitChange);
  560.                 }
  561.             }
  562.             else {
  563.                 if (gui->rect && DoMethod(gui->maingrp, MUIM_Group_InitChange)) {
  564.                     DoMethod(gui->maingrp, OM_REMMEMBER, gui->rect);
  565.                     DoMethod(gui->maingrp, MUIM_Group_ExitChange);
  566. /*                    DisposeObject(gui->rect);*/
  567.                     gui->rect = NULL;
  568.                 }
  569.             }
  570.             break;
  571.         case DEICONIFIED:
  572.             /* Work-around for a bug in Lamp.mcc */
  573.             if (gui_onlinestate < CONNECTING) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Off);
  574.             else if (gui_onlinestate == ONLINE) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Ok);
  575.             else set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Connecting);
  576.             break;
  577.     }
  578.     return(0);
  579. }
  580.  
  581.  
  582. void gui_state(enum OnlineState s)
  583. {
  584.     struct DateStamp ds;
  585.     struct DateStamp *rds;
  586.     u_long tmp;
  587.     static char title[128], buf[128];
  588.  
  589.     gui_onlinestate = s;
  590.  
  591.     switch (s) {
  592.         case DISCONNECTED:
  593.             prf_event(PRFE_DISCONNECT);
  594.             DoMethod(gui->WI_Hotlist, HOTLIST_SIGNOFF_ALL);
  595.             gui->OnlineSince = 0;
  596.             gui->Libraries = 0;
  597.             gui->Songs     = 0;
  598.             gui->Gigabytes = 0;
  599.             nap_server[0] = '\0';
  600.             nap_port   = 0;
  601.         case OFFLINE:    /* Offline */
  602.             set(gui->inbut, MUIA_Disabled, FALSE);
  603.             set(gui->outbut, MUIA_Disabled, TRUE);
  604.             set(gui->rebut, MUIA_Disabled, TRUE);
  605.  
  606.             sprintf(title, "Amster v%s · %s", AMSTER_VERSION, MSG_MAIN_TITLE_NOTCONNECTED);
  607.             set(gui->win, MUIA_Window_Title, title);
  608.  
  609.             /* Work-around for a bug in Lamp.mcc */
  610.             get(gui->app, MUIA_Application_Iconified, &tmp);
  611.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Off);
  612.  
  613.             DoMethod(gui->searchpanel, SEARCH_CLEAR, CLEAR_ALL);
  614.             DoMethod(gui->WI_Hotlist, HOTLIST_CLEAR, CLEAR_ALL);
  615.             gui_appicon(2);
  616.             break;
  617.         case CONNECTING:    /* Connecting */
  618.             set(gui->inbut, MUIA_Disabled, TRUE);
  619.             set(gui->outbut, MUIA_Disabled, FALSE);
  620.  
  621.             sprintf(title, "Amster v%s · %s", AMSTER_VERSION, MSG_MAIN_TITLE_NOTCONNECTED);
  622.             set(gui->win, MUIA_Window_Title, title);
  623.  
  624.             /* Work-around for a bug in Lamp.mcc */
  625.             get(gui->app, MUIA_Application_Iconified, &tmp);
  626.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Connecting);
  627.  
  628.             set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_CONNECTING);
  629.             break;
  630.         case LOGGING_IN:    /* Logging in */
  631.             prf_event(PRFE_CONNECT, nap_server, (int)nap_port);
  632.             set(gui->inbut, MUIA_Disabled, TRUE);
  633.             set(gui->outbut, MUIA_Disabled, FALSE);
  634.             set(gui->rebut, MUIA_Disabled, FALSE);
  635.  
  636.             rds = DateStamp(&ds);
  637.             sprintf(buf, "Amster v%s · %s", AMSTER_VERSION, MSG_MAIN_TITLE_CONNECTEDSINCE);
  638.             sprintf(title, buf, nap_server, nap_port, rds->ds_Minute/60, rds->ds_Minute%60, rds->ds_Tick/50);
  639.             set(gui->win, MUIA_Window_Title, title);
  640.             gui->OnlineSince = rds->ds_Days*24*60*60 + rds->ds_Minute*60 + rds->ds_Tick/TICKS_PER_SECOND;
  641.  
  642.             /* Work-around for a bug in Lamp.mcc */
  643.             get(gui->app, MUIA_Application_Iconified, &tmp);
  644.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_SendingData);
  645.  
  646.             break;
  647.         case ONLINE:    /* Online */
  648.             set(gui->inbut,  MUIA_Disabled, TRUE);
  649.             set(gui->outbut, MUIA_Disabled, FALSE);
  650.             set(gui->rebut,  MUIA_Disabled, FALSE);
  651.  
  652.             /* Work-around for a bug in Lamp.mcc */
  653.             get(gui->app, MUIA_Application_Iconified, &tmp);
  654.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Ok);
  655.  
  656.             gui_appicon(1);
  657.             break;
  658.     }
  659. }
  660.  
  661.  
  662. void gui_srvstat(int Libraries, int Songs, int Gigabytes)
  663. {
  664.     gui_stat((char *)MSG_STATUS2_SONGSONLINE, Songs, Libraries, Gigabytes);
  665.  
  666.     gui->Songs     = Songs;
  667.     gui->Libraries = Libraries;
  668.     gui->Gigabytes = Gigabytes;
  669. }
  670.  
  671.  
  672. void gui_found(song s, int type)
  673. {
  674.     if (type == 0) DoMethod(gui->searchpanel, SEARCH_FOUND, s);
  675.     else if (type == 1) DoMethod(gui->WI_Hotlist, HOTLIST_FOUND, s);
  676. }
  677.  
  678.  
  679. void localize_array(char *array[])
  680. {
  681.     char **x;
  682.  
  683.     for (x=array;*x;x++)
  684.         *x = (char *)((struct FC_String *)(*x))->msg;
  685. }
  686.  
  687.  
  688. void gui_stat(char *msg, ...)
  689. {
  690.     static char buf[256];
  691.     struct Hook hook;
  692. #ifdef __PPC__
  693.     va_list ap;
  694.     ULONG arg[32];
  695.     int args = 0, i;
  696.  
  697.     for (i=0; msg[i] != '\0'; i++) {
  698.         if (msg[i] == '%' && msg[i+1] != '%') args++;
  699.     }
  700.  
  701.     va_start(ap, msg);
  702.     for (i=0; i<args; i++) {
  703.         arg[i] = va_arg(ap, ULONG);
  704.     }
  705.     va_end(ap);
  706. #endif
  707.  
  708.     InitHook(&hook, putChar, buf);
  709.  
  710. #ifdef __PPC__
  711.     FormatString(locale, msg, &arg[0], &hook);
  712. #else
  713.     FormatString(locale, msg, &msg+1, &hook);
  714. #endif
  715.  
  716. /*
  717.     va_start(ap,msg);
  718.     vsprintf(buf,msg,ap);
  719.     va_end(ap);
  720. */
  721.  
  722.  
  723. /*
  724.     RawDoFmt(msg, &ap, RAWDOFMT_COPY, &buf);
  725. */
  726.  
  727.     set(gui->stat, MUIA_Text_Contents, buf);
  728. }
  729.  
  730.  
  731. void gui_appicon(int t)
  732. {
  733.     static struct DiskObject *on, *off;
  734.  
  735.     switch(t) {
  736.         case 0:
  737.             on = GetDiskObject("PROGDIR:Icons/Amster_online");
  738.             off = GetDiskObject("PROGDIR:Icons/Amster_offline");
  739.             break;
  740.  
  741.         case -1:
  742.             if (on) FreeDiskObject(on);
  743.             if (off) FreeDiskObject(off);
  744.             break;
  745.  
  746.         case 1:
  747.             if (on) set(gui->app, MUIA_Application_DiskObject, on);
  748.             break;
  749.  
  750.         case 2:
  751.             if (off) set(gui->app, MUIA_Application_DiskObject, off);
  752.             break;
  753.  
  754.     }
  755. }
  756.